package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.entity.dto.QuestionFormDTO;
import com.tianji.learning.entity.query.QuestionPageQuery;
import com.tianji.learning.entity.vo.QuestionVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 互动提问的问题表 控制器
 * </p>
 *
 * @author lemon
 */
@Api(tags = "互动问题相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/questions")
public class InteractionQuestionController {

    private final IInteractionQuestionService interactionQuestionService;

    @ApiOperation("新增互动问题")
    @PostMapping
    public void addInteractionQuestion(@RequestBody @Validated QuestionFormDTO dto) {
        interactionQuestionService.addInteractionQuestion(dto);
    }

    @ApiOperation("修改互动问题")
    @PutMapping("{id}")
    public void updateInteractionQuestion(@PathVariable("id") Long id, @RequestBody QuestionFormDTO dto) {
        interactionQuestionService.updateInteractionQuestion(id, dto);
    }

    @ApiOperation("回显互动问题")
    @GetMapping("{id}")
    public QuestionVO getInteractionQuestion(@PathVariable("id") Long id) {
        return interactionQuestionService.getInteractionQuestion(id);
    }

    @ApiOperation("用户端分页查询问题")
    @GetMapping("page")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery query) {
        return interactionQuestionService.queryQuestionPage(query);
    }

    @ApiOperation("删除互动问题")
    @DeleteMapping("{id}")
    public void deleteInteractionQuestion(@PathVariable("id") Long id) {
        interactionQuestionService.removeInteractionQuestion(id);
    }
}
